import Vue from 'vue'
// 自定义指令
export default {
  install () {
    const f = (el) => {
      let finding = false
      if (el.nodeName === 'INPUT' || el.nodeName === 'TEXTAREA') {
        el.focus()
        finding = true
      } else {
        const ipt = el.querySelector('input')
        const ta = el.querySelector('textarea')
        if (ipt && ipt.nodeName === 'INPUT') {
          ipt.focus()
          finding = true
        }
        if (ta && ta.nodeName === 'TEXTAREA') {
          ta.focus()
          finding = true
        }
        if (finding === false) {
          throw new Error('没有找到')
        }
      }
    }
    Vue.directive('fofo', {
      inserted (el) {
        f(el)
      },
      update (el) {
        f(el)
      }
    })
  }
}
